package cc.vv.btpartyjob.partyservice.adapter

import android.annotation.SuppressLint
import android.view.View
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import cc.vv.baselibrary.adapter.SimpleCommonAdapter
import cc.vv.baselibrary.adapter.holder.ExtendViewHolder
import cc.vv.btpartyjob.partyservice.R
import cc.vv.btpartyjob.partyservice.module.bean.MineWishClaimBean

/**
 * 我的心愿认领adapter
 * Created by Chen.qi on 2018/10/24.
 */
class MineWishAdapter(layoutResId: Int) : SimpleCommonAdapter<MineWishClaimBean>(layoutResId) {
    @SuppressLint("SetTextI18n")
    override fun convert(helper: ExtendViewHolder, item: MineWishClaimBean, position: Int) {
        //内容
        helper.getView<TextView>(R.id.tv_imwT_content)?.text = item.wishConetnt

        //许愿人
        helper.getView<TextView>(R.id.tv_imwT_xPerson)?.text = "许愿人："

        //发布人
        helper.getView<TextView>(R.id.tv_imwT_xyName)?.text = item.name

        //联系方式
        helper.getView<TextView>(R.id.tv_imwT_telPhone)?.text = item.mobile

        //地址
        helper.getView<TextView>(R.id.tv_imwT_address)?.text = item.addr

        //起止时间
        try {
            val startTime = item.startTime?.substring(0, 10)
            val endTime = item.endTime?.substring(0, 10)
            helper.getView<TextView>(R.id.tv_imwT_time)?.text = "时间段：$startTime 至$endTime"
        } catch (e: Exception) {
            e.printStackTrace()
        }

        val allInfo = helper.getView<LinearLayout>(R.id.ll_imwT_allInfo)
        val openPic = helper.getView<ImageView>(R.id.tv_imwT_openPic)
        if (item.selecOpen) {
            allInfo?.visibility = View.VISIBLE
            openPic?.isSelected = true
        } else {
            allInfo?.visibility = View.GONE
            openPic?.isSelected = false
        }
        helper.addOnClickListener(R.id.ll_imwT_detail)

        //未认领
        val ivStatus = helper.getView<ImageView>(R.id.iv_imvT_status)
        if (item.claimState == 1) {
            //认领成功
            ivStatus.setImageResource(R.mipmap.icon_server_rlcg)
        } else {
            //认领失败
            ivStatus.setImageResource(R.mipmap.icon_server_rlsb)
        }
    }
}